package com.exam.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/delay")
public class DelayController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public static final String DELAY_EXCHANGE_NAME = "delay_send_exchange";
    public static final String DELAY_ROUTING_KEY = "delay_routing_key";

    /**
     * 发送消息到RabbitMQ延迟队列
     *
     * @param message 要发送的消息内容
     * @return 返回添加当前时间后的消息内容
     */
    @RequestMapping("/send")
    public String send(String message) {
        message = message + "现在时间：" + new Date();
        rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_ROUTING_KEY, message);
        return message;
    }
}
